﻿using RabbitMQ.Client;

namespace Maltose.MessageQueue
{

    /// <summary>
    /// 消息队列_主机
    /// </summary>
    public class MessageQueueHost
    {
        /// <summary>
        /// MQ连接
        /// </summary>
        public IConnection Connection { get; private set; }

        /// <summary>
        /// 通信频道
        /// </summary>
        public IModel Channel { get; private set; }


        /// <summary>
        /// 消息队列_消费者订阅主机
        /// </summary>
        public MessageQueueHost(MessageQueueConnect connect)
        {
            Connection = connect.Connection;
            Channel = Connection.CreateModel();
        }

        /// <summary>
        /// 关闭连接跟通信通道 跟释放资源
        /// </summary>
        public void ColseConnect()
        {
            if (Connection.IsOpen)
            {
                Connection.Close();
                Connection.Dispose();
            }
        }
    }
}
